import request from '@/axios'
import { LoginUserData, RefreshTokenType, UserType } from './types'

export const loginApi = (data: UserType): Promise<IResponse<LoginUserData>> => {
  return request.post({ url: '/auth/login', data })
}

export const loginOutApi = (): Promise<IResponse> => {
  return request.get({ url: '/auth/logout' })
}

export const heartbeatApi = (): Promise<IResponse> => {
  return request.get({ url: '/auth/heartbeat' })
}

export const refreshTokenApi = (RefreshToken?: string): Promise<IResponse<RefreshTokenType>> => {
  return request.get({
    url: '/auth/refresh',
    headers: { RefreshToken }
  })
}

export const getUserListApi = ({ params }: AxiosConfig) => {
  return request.get<{
    code: string
    data: {
      list: UserType[]
      total: number
    }
  }>({ url: '/mock/user/list', params })
}
